
package cn.com.czpb.client.utils;

import android.app.Activity;
import android.content.Intent;
import android.webkit.JavascriptInterface;

import cn.com.czpb.client.model.news.NewsDetailBean;
import cn.com.czpb.client.module.news.activity.NewsAlbum_Activity;

import java.util.ArrayList;

public class MyJavascriptInterface {

	private Activity context;
	private NewsDetailBean ndb;

	public MyJavascriptInterface(Activity context){
		this.context = context;
		
	}
	
	public void setNewsDetailBean(NewsDetailBean ndb){
		this.ndb=ndb;
	}

	public MyJavascriptInterface(Activity context, NewsDetailBean ndb){
		this.context = context;
		this.ndb=ndb;
	}

	@JavascriptInterface
	public void openImages(String curentImg, String allImg){

		int position = 0;
		String[] temp = null;
		ArrayList<String> list = new ArrayList<>();
		temp = allImg.split(",");
		for (int i = 0;i<temp.length;i++){
			String img = temp[i];
			LogUtils.e("img-->"+img);
			list.add(img);
			if (img.equals(curentImg)){
				position = i;
			}
		}
		Intent intent = new Intent();
		intent.putExtra("from", "news");
		intent.putExtra("position", position);
		intent.putStringArrayListExtra("imags",list);
		//intent.putExtra("imags",temp);
		intent.putExtra("ndb", ndb);
		intent.setClass(context, NewsAlbum_Activity.class);
		context.startActivity(intent);
	}
}